package com.platform.acl.listener;


import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import com.platform.acl.entity.excel.UserInfo;
import com.platform.acl.service.UserRoleService;

import java.util.Map;

/**
 * @PackageName:com.platform.acl.listener
 * @ClassName:ExcelListener
 * @Description:
 * @Author: LJH
 * @Since:2022/3/2
 */
public class ExcelListener extends AnalysisEventListener<UserInfo> {

    private UserRoleService userRoleService;

    //通过构造器传参方式 传递 spring容器中实例好的userRoleService
    public ExcelListener(UserRoleService userRoleService) {
        this.userRoleService = userRoleService;
    }

    public ExcelListener() {
    }

    //一行行读excel
    @Override
    public void invoke(UserInfo userInfo, AnalysisContext analysisContext) {

        userRoleService.saveUserMessage(userInfo);

    }

    //读取excel表头信息
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        //System.out.println(headMap.get(1));
        super.invokeHeadMap(headMap, context);
    }

    //读取完成后执行
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}